setup

conda install -c conda-forge pyhocon

read

temp.config

client = {
  user = adsf
  password = adsf
}

blah = {
  blah = {
    blah = blah
  }
}
import pyhocon
config = pyhocon.ConfigFactory.parse_file("temp.config")
type(config)
#  <class 'pyhocon.config_tree.ConfigTree'>
isinstance(config, dict)
#  True
config.get('blah')
#  ConfigTree([('blah', ConfigTree([('blah', 'blah')]))])
config.get('blah', 'blah')
#  ConfigTree([('blah', ConfigTree([('blah', 'blah')]))])
config.get('blah', 'blah').keys()
#  odict_keys(['blah'])
config.get('blah', 'blah').get('blah')
#  ConfigTree([('blah', 'blah')])

create

TODO


write

# convert ConfigTree to string
config = pyhocon.HOCONConverter.convert(
    config,
    output_format='hocon',
    indent=2,
    compact=False
)
# write file
with open("temp.config", 'w') as f:
    f.write(config)

convert

json

# convert ConfigTree to json string
config = pyhocon.HOCONConverter.to_json(config)
# convert json string to dict
config = json.loads(config)